package com.kkb.kkbadmin.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kkb.kkbadmin.dao.UserRoleMapper;
import com.kkb.kkbadmin.domain.UserRole;
import com.kkb.kkbadmin.service.UserRoleService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户角色关联表 服务实现类
 *
 * @author 赵裕源
 * @since 2021-08-15
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {

    /**
     * 根据角色Id找到用户Id列表List
     *
     * @param roleId 角色Id
     * @return 用户Id列表List
     */
    @Override
    public List<Long> findUserIdListByRoleId(Long roleId) {

        List<UserRole> list = this.lambdaQuery()
                .eq(ObjectUtil.isNotNull(roleId), UserRole::getRoleId, roleId)
                .list();

        // 直接使用stream流获取id列表
        return list.stream().map(UserRole::getId).collect(Collectors.toList());
    }
}
